﻿namespace IOP.OpenType.Tables
{
    /// <summary>
    /// 度量表
    /// </summary>
    public class HmtxTable : Table
    {
        /// <summary>
        /// 度量数据
        /// </summary>
        public LongHorMetric[] HMetrics { get; set; }
        /// <summary>
        /// 左边距
        /// </summary>
        public short[] LeftSideBearings { get; set; }

        /// <summary>
        /// 根据GId获取横向度量值
        /// </summary>
        /// <param name="gId"></param>
        /// <returns></returns>
        public LongHorMetric GetHorMetric(uint gId)
        {
            if (gId >= HMetrics.Length)
            {
                LongHorMetric end = HMetrics[^1];
                return new LongHorMetric()
                {
                    AdvanceWidth = end.AdvanceWidth,
                    LeftSideBearing = LeftSideBearings[gId - HMetrics.Length]
                };
            }
            else return HMetrics[gId];
        }
    }

    /// <summary>
    /// 
    /// </summary>
    public struct LongHorMetric
    {
        /// <summary>
        /// 
        /// </summary>
        public ushort AdvanceWidth;
        /// <summary>
        /// 
        /// </summary>
        public short LeftSideBearing;
    }
}
